<?php


namespace app\controller;

use app\common\controller\BaseController;
use app\common\service\content\CategoryService;
use app\common\service\content\ContentService;
use app\common\service\setting\CarouselService;
use app\api\service\IndexService;
use hg\apidoc\annotation as Apidoc;
use think\facade\View;

/**
 * @Apidoc\Title("首页")
 * @Apidoc\Group("index")
 * @Apidoc\Sort("100")
 */
class News extends BaseController
{
    /**
     * @Apidoc\Title("首页")
     * @Apidoc\NotHeaders()
     * @Apidoc\NotQuerys()
     * @Apidoc\NotParams()
     */
    public function index()
    {
        $pathinfo = $this->request->pathinfo(); // 获取路径信息 "news/industry?page=1"
        $path = getUrlPath($pathinfo);
        $info = CategoryService::getUrlId($path);

        $id = 6;
        if (!empty($info)) {
            $id = $info['category_id'];
        } else {
            $info = CategoryService::info(6);
        }
        $page = request()->param('page', 1);
        $menu = CategoryService::getSubMenu(6);
        View::assign('menu', $menu);
        $ids = CategoryService::getSubMenuIds($id);
        $where[] = ['category_ids', 'in', $ids];
        $where[] = ['type', '=', 1];
        $list =   ContentService::lis($where, $page, 12);

        foreach ($list as $key => $value) {
            $date = date('Y-m-d', strtotime($value['create_time']));
            $list[$key]['create_time'] = $date;
        }

        View::assign('list', $list);
        View::assign('info', $info);


        return view('news/list_article');
    }
    // public function company()
    // {
    //     $menu = CategoryService::getSubMenu(6);
    //     View::assign('menu', $menu);
    //     return view('list_article');
    // }

    public function faq()
    {
        $page = request()->param('page', 1);
        $where = where_disdel();
        $where[] = ['category_ids', 'in', [24]];
        $list =   ContentService::lis($where, $page, 12);
        foreach ($list as &$item) {
            $item['remark'] = nl2br($item['remark']);
        }
  
        View::assign('list', $list);

        return view('faq');
    }
    public function article($id)
    {

        $info = ContentService::info($id);
        View::assign('info', $info);
        $title = $info['name'];
        $keywords = $info['keywords'];
        $description = $info['description'];
        View::assign('title', $title);
        View::assign('keywords', $keywords);
        View::assign('description', $description);
        $prev_info = ContentService::prevNext($id, 'prev');
        $next_info = ContentService::prevNext($id, 'next');
        View::assign('prev_info', $prev_info);
        View::assign('next_info', $next_info);
        $category_ids = $info['category_ids'];
        $category_info = CategoryService::info($category_ids[0]);
        $bannerUrl = $category_info['image_url'];
        View::assign('bannerUrl', $bannerUrl);
        View::assign('category_info', $category_info);

        $where[] = ['category_ids', 'in', $category_ids[0]];
        $where[] = ['type', '=', 1];
        $linklist =   ContentService::lis($where, 1, 5);

        View::assign('linklist', $linklist);
        $position[] = [
            'name' => $category_info['category_name'],
            'url' => $category_info['url']
        ];
        $position[] = [
            'name' => $info['name'],
            'url' => ''
        ];
        View::assign('position', $position);
        return view('news/article');
    }
}
